<?php 
	define(SEPARATE, '/');

	echo '<div class="floattop"><div class="itemtitle"><h3>视频分类</h3><ul class="tab1">';
	if(empty($operation) || $operation=='add'){
		echo '<li class="current"><a href="admin.php?action=videocate&operation=add" style="text-decoration:none;"><span style="color:#666;">添加</span></a></li><li><a href="admin.php?action=videocate&operation=manage" style="text-decoration:none;"><span style="color:#666;">管理</span></a></li>';
	} elseif($operation=='manage'){
		echo '<li><a href="admin.php?action=videocate&operation=add" style="text-decoration:none;"><span style="color:#666;">添加</span></a></li><li class="current"><a href="admin.php?action=videocate&operation=manage" style="text-decoration:none;"><span style="color:#666;">管理</span></a></li>';
	}
	echo '</ul></div></div>';

	if($operation=='add'){
		echo '<form method="post" id="videocate" action="admin.php?action=videocate&operation=set">';
		echo '分类名称：<input type="text" name="cate_name"><br>';
		echo '分类排序：<input type="text" name="cate_sort" value="255"><br>';
		echo '<input type="submit" class="btn" id="submit_cardsubmit" name="cardsubmit" title="按 Enter 键可随时提交您的修改" value="提交">';
	}

	if($operation=='set'){
		if(empty($_POST['cate_name']) || empty($_POST['cate_sort'])){
			echo '<script type="text/Javascript">alert("请填写完整信息!");window.history.back();</script>';
		}else{
			$cate_name = trim($_POST['cate_name']);
			$cate_sort = trim($_POST['cate_sort']);
			$add_time = time();
			C::t('home_videocate')->add_videocate($cate_name,$cate_sort,$add_time);
			echo '<script type="text/Javascript">alert("分类添加成功!");';
			echo 'window.location="'.ADMINSCRIPT.'?action=videocate&operation=manage";';
			echo '</script>';
		}
	} elseif($operation=='manage' || empty($operation)){
		if(empty($_POST)){
			$re = C::t('home_videocate')->get_all_cate();
			if(!empty($re)){
				echo '<form action="admin.php?action=videocate&operation=manage" method="post">';
				echo '<table>';
				echo '<tr>';
				echo '<th>分类编号</th>';
				echo '<th>分类名称</th>';
				echo '<th>分类排序</th>';
				echo '<th>是否删除</th>';
				foreach($re as $val){
					echo '<tr>';
					echo '<td align="center">'.$val['cate_id'].'</td>';
					echo '<td align="center"><input type="text" name="val['.$val['cate_id'].'][name]" value="'.$val['cate_name'].'"></td>';
					echo '<td align="center"><input type="text" name="val['.$val['cate_id'].'][sort]" value="'.$val['cate_sort'].'"></td>';
					echo '<td align="center"><input type="checkbox" name="val['.$val['cate_id'].'][del]" value="'.$val['cate_id'].'">删除</td>';
					echo '</tr>';
				}
				echo '</table>';
				echo '<input type="submit" value="提交">';
				echo '</form>';
			}	
		}else{
			foreach ($_POST['val'] as $key => $val) {
				C::t('home_videocate')->update_cate($key,$val['del'],$val['name'],$val['sort']);
			}
			echo '<script type="text/Javascript">alert("操作成功!");window.location.reload();</script>';
		}
	}

?>